package cc.flyflow.web.controller.process;

import cc.flyflow.common.constants.ValidGroup;
import cc.flyflow.biz.process.service.IProcessService;
import cc.flyflow.biz.vo.ProcessVO;
import cc.flyflow.common.dto.R;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 流程接口
 *
 * @author Jyl
 */
@Validated
@RestController
@RequestMapping(value = "process")
public class ProcessController
{

    @Resource
    private IProcessService processService;

    /**
     * 根据流程唯一标识查询流程列表
     *
     * @param uniqueId
     * @return
     */
    @GetMapping("/getListByUniqueId/{uniqueId}")
    public R<ProcessVO> getListByUniqueId(@PathVariable String uniqueId)
    {
        return processService.getListByUniqueId(uniqueId);
    }

    /**
     * 设置主流程
     *
     * @param flowId
     * @return
     */
    @PostMapping("setMainProcess/{flowId}")
    public R setMainProcess(@PathVariable String flowId)
    {
        return processService.setMainProcess(flowId);
    }

    /**
     * 获取详细数据
     *
     * @param flowId 流程id
     * @return
     */
    @GetMapping("getDetail")
    public R<ProcessVO> getDetail(String flowId)
    {
        return processService.getDetail(flowId);
    }

    /**
     * 创建流程
     *
     * @param processVO
     * @return
     */
    @PostMapping("create")
    public R create(@Validated(value = ValidGroup.Crud.Create.class) @RequestBody ProcessVO processVO)
    {
        return processService.create(processVO);
    }

    /**
     * 编辑表单
     *
     * @param flowId  摸板ID
     * @param type    类型 stop using delete
     * @param groupId 流程组id
     * @return 操作结果
     */
    @PutMapping("update/{flowId}")
    public R update(@PathVariable String flowId,
                    @RequestParam String type,
                    @RequestParam(required = false) Long groupId)
    {
        return processService.update(flowId, type, groupId);
    }
}
